import logging

import yagmail
import traceback
from conf.config import send_as_mail
logger = logging.getLogger('log')


class Mail:
    def __init__(self, user="haoaremesda@163.com", host="smtp.163.com", password="FVUNMOHOTHYSEPNP"):
        self.yag = yagmail.SMTP(user=user, host=host, password=password)

    def send_mail(self, title, contents, other_side=send_as_mail):
        try:
            self.yag.send(other_side, title, contents)
            self.yag.close()
        except Exception:
            logger.error(f"{traceback.format_exc()}")
